<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id="app">
    <input v-model="inputVal">
    <button @click = "handSubmit">提交</button>

    <ul>
        <todo-item
        v-for="(item,index) of list"
        :key="index"
        :content="item"
        :index = "index"
        @delete = "handDelete">

        </todo-item>
    </ul>

</div>

<script>
    Vue.component('todo-item',{
        props:['content','index'],
        template:'<li @click="handClick">{{ content }}</li>',
        methods:{
            handClick:function () {
                this.$emit('delete',this.input)
            }
        }
    })

    new Vue({
        el:'#app',
        data:{
            inputVal: '',
            list:[]

        },
        methods:{
           handSubmit:function () {
               this.list.push(this.inputVal)
               this.inputVal =''

           },
           handDelete:function (index) {
               this.list.splice(index,1)

           }
        }
    })
</script>
</body>
</html>